package universum.engine.environment;

import com.miriamlaurel.pms.Asynchronous;
import com.miriamlaurel.pms.Listener;
import universum.bi.Location;

import java.util.List;

public class EnvironmentProxy implements IEnvironmentProxy {
    private IEnvironment _env;
    private IEnvironmentServiceProxyCallback _envServ;
    
     public static enum EventType {NewMessage}
    public EnvironmentProxy(IEnvironmentServiceProxyCallback myEnvService, IEnvironment myEnv)
    {
        _env = myEnv;
        _envServ = myEnvService;
    }


    public String getName() {
        return _env.getName();
    }

    public int getVersion() {
        return _env.getVersion();
    }
    public String getShortName()
    {
        return _env.getShortName() ;
    }

    public List<IAvailableMessage> getMessages(Location pos, int callerID) {
        return _env.getMessages(pos, callerID);
    }


    @Asynchronous
            @Listener
            void $(EventType e)
        {
            switch(e)
            {
            case NewMessage : sendMessage(); break;
            }
        }
    private void sendMessage()
    {
        IBroadcastingFrame frame;
        IBroadcastingParams params ;
        IEnvControlMessage msg ;
        while (_envServ.hasWaitingFrames() )
        {
            frame = _envServ.getFrame() ;
            params = frame.getParams() ;
            msg = frame.getMessage();
            _env.addMessage(msg,params);
        }
    }
    public void preRound(int roundNumber)
    {
        _env.preRound(roundNumber);
    }
    public void postRound()
    {
        _env.postRound();
    }
}
